package com.example.peanutsubway.web;

import com.alibaba.fastjson.JSONObject;
import com.example.peanutsubway.annotation.ResponseTypeAnnotation;
import com.example.peanutsubway.entity.Game;
import com.example.peanutsubway.entity.PageInfo;
import com.example.peanutsubway.myEnum.ResponseEnum;
import com.example.peanutsubway.service.impl.GameServiceImpl;

import javax.servlet.annotation.WebServlet;
import java.util.List;

/**
 * @Author：liyangsong
 * @Version：1.0
 * @Date：2021/10/10-21:05
 * @Since:jdk1.8
 * @Description:
 */


@WebServlet("/game.do")
public class GameServlet extends BaseServlet<Game> {
    private GameServiceImpl gameService = new GameServiceImpl();

    /**
     * 游戏列表
     *
     * @param game
     * @return
     */
    @ResponseTypeAnnotation(type = ResponseEnum.AJAX)
    public String showAllGame(Game game) {
        String nowPage = request.getParameter("nowPage");
        String pageNum = request.getParameter("pageSize");
        PageInfo pageInfo = gameService.showAllGame(game, nowPage, pageNum);
        String jsonString = JSONObject.toJSONString(pageInfo);
        return jsonString;
    }

    /**
     * 添加游戏
     * @param game
     * @return
     */
    @ResponseTypeAnnotation(type = ResponseEnum.AJAX)
    public String addGame(Game game) {
        Boolean falg = gameService.addGame(game);
        String message = falg?"添加成功":"添加失败";
        return message;
    }

    /**
     * 修改游戏
     * @param game
     * @return
     */
    @ResponseTypeAnnotation(type = ResponseEnum.AJAX)
    public String updateGame(Game game){
        Boolean aBoolean = gameService.updateGame(game);
        String message = aBoolean?"修改成功":"修改失败";
        return message;
    }

    /**
     * 删除游戏
     * @param game
     * @return
     */
    @ResponseTypeAnnotation(type = ResponseEnum.AJAX)
    public String deleteGame(Game game){
        Boolean aBoolean = gameService.deleteGame(game.getGid());
        String message = aBoolean?"删除成功":"删除失败";
        return message;
    }


    /**
     * ios地址
     * @param game
     * @return
     */
    @ResponseTypeAnnotation(type = ResponseEnum.AJAX)
    public String iosurlList(Game game){
        List<Game> games = gameService.iosUrlList(game);
        String jsonString = JSONObject.toJSONString(games);
        return jsonString;
    }

    /**
     * 安卓下载地址
     * @param game
     * @return
     */
    @ResponseTypeAnnotation(type = ResponseEnum.AJAX)
    public String androidurlList(Game game){
        List<Game> games = gameService.androidUrlList(game);
        String jsonString = JSONObject.toJSONString(games);
        return jsonString;
    }

    /**
     * 游戏图标
     * @param game
     * @return
     */
    @ResponseTypeAnnotation(type = ResponseEnum.AJAX)
    public String gameiconList(Game game){
        List<Game> games = gameService.gameiconUrlList(game);
        String jsonString = JSONObject.toJSONString(games);
        return jsonString;
    }

    /**
     * 游戏详情图片
     * @param game
     * @return
     */
    @ResponseTypeAnnotation(type = ResponseEnum.AJAX)
    public String gamepicturesList(Game game){
        List<Game> games = gameService.gamepictureList(game);
        String jsonString = JSONObject.toJSONString(games);
        return jsonString;
    }
}
